"""
    Administration application
    Handles events used for PartnerGate Administration
    (ex" /totals/partner_id)
"""
from flask import g, Blueprint
from decorators import gate_response
from models import DataAccess

admin = Blueprint('admin', __name__)


@admin.route("/total/<int:partner_id>/", methods=['GET'])
@gate_response(expires="+1h", max_age=3600)
def total(partner_id):
    total = g.db.get_total(partner_id)
    return str(total) if total > 0 else "0"

@admin.before_request
def before_request():
    g.db = DataAccess()
    pass

@admin.after_request
def after_request(response):
    g.db.close()
    return response
